package com.ballyza;

public class Compiler {

	private final CompileResult result;
	private BallyzaLexical lexical;
	private BallyzaSyntactic syntactic;
	private final AnallyzerType type;

	public Compiler(CompileResult result, AnallyzerType type) {
		this.result = result;
		this.type = type;
	}

	public BallyzaSyntactic getSyntatic() {
		return syntactic;
	}
	
	public CompileResult compile(String param) {
		if (param == null)
			throw new IllegalArgumentException("Invalid param!");

		lexical = new BallyzaLexical(param, result);
		lexical.start();
		
		if(type != AnallyzerType.Lexical) {
			syntactic = new BallyzaSyntactic(lexical, result, type == AnallyzerType.Semantic);
			syntactic.start();
		}
		
		/*if(type == AnallyzerType.Syntactic) {
			syntactic = new BallyzaSyntactic(lexical, result);
			syntactic.start();
		} else if(type == AnallyzerType.Semantic) {
			syntactic = new BallyzaSyntactic(lexical, result, true);
			syntactic.start();
		}*/

		return result;
	}

	public CompileResult getResult() {
		return result;
	}

}